import { Index } from 'index-model.js';
var index = new Index();
Page({
	data: {
		bannerHeight: Math.ceil(400.0 / 750.0 * getApp().screenWidth)
	},
  onLoad: function () {
    this._loadData();
  },
  _loadData: function (callback) {
    var that = this;
    //获得banner信息
    index.getBannerData((data) => {
      that.setData({
        bannerArr: data,
      });
    });
    //获得热卖推荐信息
    index.getClassiData((data) => {
      that.setData({
        ClassiData: data,
      });
    });
    //获得新品推荐信息
    index.getNewArrivals((data)=>{
      that.setData({
        NewData:data,
      });
    });
  },
/*
  onReady: function () {
    var totalSecond = 3600;

    var interval = setInterval(function () {
      // 秒数  
      var second = totalSecond;

      // 天数位  
      var day = Math.floor(second / 3600 / 24);
      var dayStr = day.toString();
      if (dayStr.length == 1) dayStr = '0' + dayStr;

      // 小时位  
      var hr = Math.floor((second - day * 3600 * 24) / 3600);
      var hrStr = hr.toString();
      if (hrStr.length == 1) hrStr = '0' + hrStr;

      // 分钟位  
      var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
      var minStr = min.toString();
      if (minStr.length == 1) minStr = '0' + minStr;

      // 秒位  
      var sec = second - day * 3600 * 24 - hr * 3600 - min * 60;
      var secStr = sec.toString();
      if (secStr.length == 1) secStr = '0' + secStr;

      this.setData({
        countDownDay: dayStr,
        countDownHour: hrStr,
        countDownMinute: minStr,
        countDownSecond: secStr,
      });
      totalSecond--;
      if (totalSecond < 0) {
        clearInterval(interval);
        wx.showToast({
          title: '活动已结束',
        });
        this.setData({
          countDownDay: '00',
          countDownHour: '00',
          countDownMinute: '00',
          countDownSecond: '00',
        });
      }
    }.bind(this), 1000);
  }, 
	getInviteCode: function (options) {
		if (options.uid != undefined) {
			wx.showToast({
				title: '来自用户:' + options.uid + '的分享',
				icon: 'success',
				duration: 2000
			})
		}
	},*/

	onShareAppMessage: function () {
		return {
			title: '秦岭云电商',
			desc: '致力于............',
			path: '/pages/index/index?uid=4719784'
		}
	},

  showSearch: function () {
    wx.navigateTo({
      url: '../search/search'
    });
  },
  jumpEvent: function (e) {
    var _type = e.currentTarget.dataset.type;
    var url_type = e.currentTarget.dataset.typeUrl;
    if(_type)
    {
      wx.navigateTo({
        url: url_type
      });
    }
    
  },
  goCommGoods:function(e){
    var goodsId = e.currentTarget.dataset.comid;
    //console.log(goodsId);
      wx.navigateTo({
        url: "../goods/detail/detail?objectId=" + goodsId
      });
  },
  showDetail:function(e){
    var goodsId =e.currentTarget.dataset.index;
    wx.navigateTo({
      url: "../goods/detail/detail?objectId=" + goodsId
    });
  },
  toListRecommend: function () {
    wx.navigateTo({
      url: "../goods/listRecommend/listRecommend"
    });
  },
})